﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Problema1_AbstractFactory_Singleton_ObjectPool
{
    class Program
    {
        static void Main(string[] args)
        {
            Factory factoryPtMasiniDePasageri = FactoryForPassengerCars_Singleton.getSingletonInstance();//singleton - instantiem o singura data
            List<Client> listaClienti = new List<Client>();
            string i = "-1";

            while (i!="0")
            {
                Console.Clear();
                Console.WriteLine("MENIU");
                Console.WriteLine("Tasta 1 - Adauga Client");
                Console.WriteLine("Tasta 2 - Afisare Clienti");
                Console.WriteLine("Tasta 3 - Afisare Masini pentru Un Client Selectat");
                Console.WriteLine("Tasta 4 - Adauga Masina pentru Un Client Selectat");
                Console.WriteLine("Tasta 5 - Sterge Masina");
                Console.WriteLine("Tasta 0 - EXIT");
                i=Console.ReadLine();

                if (i == "1")
                {
                    Console.WriteLine("Nume = ");
                    string nume = Console.ReadLine();
                    Console.WriteLine("Varsta = ");
                    string varsta = Console.ReadLine();

                    
                    Client client = new ClientPersoanaFizica(factoryPtMasiniDePasageri);
                    client.setNume(nume);
                    client.setVarsta(varsta);
                    listaClienti.Add(client);
                }
                if (i == "2")
                {
                    if (listaClienti.Count > 0)
                    {
                        for (int j = 0; j < listaClienti.Count; j++)
                        {
                            Console.WriteLine("Nr. Crt. " + j + " - Nume: " + listaClienti[j].getNume() + " - Varsta: " + listaClienti[j].getVarsta());
                        }
                    }
                    else
                    {
                        Console.WriteLine("Lista clienti goala...");
                    }
                    Console.ReadLine();
                }
                if (i == "3")
                {
                    Console.WriteLine("Nr. Crt. = ");
                    string kS = Console.ReadLine();

                    bool ok = false;
                    for (int j = 0; j < listaClienti.Count; j++)
                    {
                        if (kS == j.ToString())
                            ok = true;
                    }                    
                    if (ok)
                    {
                        int k = Convert.ToInt32(kS);
                        listaClienti[k].afisareMasini();
                    }
                    else
                    {
                        Console.WriteLine("Nu exista clientul...");
                    }
                    Console.ReadLine();
                }
                if (i == "4")
                {
                    Console.WriteLine("(Daca o masina de acelasi tip (Sedan/Coupe/Mini) exista pe stoc se va livra acea masina chiar daca nu corespunde tuturor optiunilor cerute - OBJECT POOLING)");
                    Console.WriteLine("Nr. Crt. = ");
                    string kS = Console.ReadLine();

                    bool ok = false;
                    for (int j = 0; j < listaClienti.Count; j++)
                    {
                        if (kS == j.ToString())
                            ok = true;
                    }

                    if (ok)
                    {
                        int k = Convert.ToInt32(kS);

                        Console.WriteLine("Tip = ? (0 - sedan/1 - mini/2 - coupe)");                        
                        string tipS = Console.ReadLine();
                        int tip;
                        if ((tipS == "0") || (tipS == "1") || (tipS == "2"))
                            tip = Convert.ToInt32(tipS);
                        else
                        {
                            Console.WriteLine("Eroare...");
                            continue;
                        }
                        
                        Console.WriteLine("Culoare = ? (0 - alb/1 - negru)");
                        string culS = Console.ReadLine();
                        int cul;
                        if ((culS == "0") || (culS == "1"))
                            cul = Convert.ToInt32(culS);
                        else
                        {
                            Console.WriteLine("Eroare...");
                            continue;
                        }
                        
                        Console.WriteLine("Transmisie = ? (0 - manuala/1 - automata)");
                        string trsS = Console.ReadLine();
                        int trs;
                        if ((trsS == "0") || (trsS == "1"))
                            trs = Convert.ToInt32(trsS);
                        else
                        {
                            Console.WriteLine("Eroare...");
                            continue;
                        }


                        Console.WriteLine("Climatizare = ? (0 - manuala/1 - automata)");
                        string clmS = Console.ReadLine();
                        int clm;
                        if ((clmS == "0") || (clmS == "1"))
                            clm = Convert.ToInt32(clmS);
                        else
                        {
                            Console.WriteLine("Eroare...");
                            continue;
                        }

                        Console.WriteLine("Tapiterie = ? (0 - stoda/1 - piele)");
                        string tapS = Console.ReadLine();
                        int tap;
                        if ((tapS == "0") || (tapS == "1"))
                            tap = Convert.ToInt32(tapS);
                        else
                        {
                            Console.WriteLine("Eroare...");
                            continue;
                        }

                        listaClienti[k].comandaMasina(tip, cul, trs, clm, tap);
                    }
                    else
                    {
                        Console.WriteLine("Nu exista clientul...");
                        Console.ReadLine();
                    }
                    
                }
                if (i == "5")
                {
                    Console.WriteLine("Nr. Crt. = ");
                    string kS = Console.ReadLine();
                    Console.WriteLine("Nr. Masina = ");
                    string nr = Console.ReadLine();

                    bool ok = false;
                    for (int j = 0; j < listaClienti.Count; j++)
                    {
                        if (kS == j.ToString())
                            ok = true;
                    }
                    if (ok)
                    {
                        int k = Convert.ToInt32(kS);
                        listaClienti[k].stergeMasina(Convert.ToInt32(nr));
                    }

                }
            }
        }
    }
}
